<?php
/*
 * Created on Feb 19, 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

class TimeZone
{
	public function TimeZone()
	{
		
	}
	
	function getTimezoneOffset($sourceTZ, $target_dt = null) 
	{
	    if($target_dt === null) {
	        if(!is_string($target_dt = date_default_timezone_get())) {
	            return false; // A UTC timestamp was returned -- bail out!
	        }
	    }
	    
	    $targetDTZ = new DateTimeZone($target_dt);
	    $sourceDTZ = new DateTimeZone($sourceTZ);
	    
	    $target_dt 	= new DateTime("now", $targetDTZ);
	    $source_dt 	= new DateTime("now", $sourceDTZ);
	    
	    $offset = $targetDTZ->getOffset($target_dt) - $sourceDTZ->getOffset($source_dt);
    	
    	return $offset;
	}
	
	function getTime($time, $sourceTZ, $targetTZ)
	{
	    $sourceDTZ	= new DateTimeZone($sourceTZ);
	    $targetDTZ 	= new DateTimeZone($targetTZ);
	    
	    $source_dt 	= new DateTime($time, $sourceDTZ);
	    $target_dt 	= new DateTime($time, $targetDTZ);
	    
	    $offset = $targetDTZ->getOffset($target_dt) - $sourceDTZ->getOffset($source_dt);
	    
	    $offset_time = strtotime($time) + $offset;
	    
	    return date('Y-m-d H:i:s', $offset_time);
	}
	
	function getNowTime($targetTZ, $format)
	{
	    $time 		= 'now';
	    $sourceTZ 	= 'UTC';
	    
	    $sourceDTZ	= new DateTimeZone($sourceTZ);
	    $targetDTZ 	= new DateTimeZone($targetTZ);
	    
	    $source_dt 	= new DateTime($time, $sourceDTZ);
	    $target_dt 	= new DateTime($time, $targetDTZ);
	    
	    $offset = $targetDTZ->getOffset($target_dt) - $sourceDTZ->getOffset($source_dt);
	    
	    $offset_time = strtotime($time) + $offset;
	    
	    return date($format, $offset_time);
	}
}
?>
